import 'dart:typed_data';

import 'package:bluetooth_protocols_plugin/src/base/message/public_instruction_message_base.dart';

import '../../../../library.dart';

// Lorin指令
class LorinPublicInstructionMessage
    extends PublicInstructionMessageBase<LorinMessage> {
  @override
  LorinMessage get getSnIntrMsg =>
      LorinMessage.from(LorinPublicRequestBody.getSN);

  @override
  LorinMessage get checkSafeConnectionResultIntrMsg =>
      LorinMessage.from(LorinPublicRequestBody.checkSafeConnectionResult);

  @override
  LorinMessage get getProductModelIntrMsg =>
      LorinMessage.from(LorinPublicRequestBody.getProductModel);

  @override
  LorinMessage getFirmwareVersionIntrMsg({
    int? targetDevice,
  }) =>
      LorinMessage.from(LorinPublicRequestBody.getFirmwareVersion(
          targetDevice: targetDevice));

  @override
  LorinMessage establishSafeConnectionIntrMsg(Uint8List bytes) =>
      LorinMessage.from(LorinPublicRequestBody.establishSafeConnection(bytes));

  @override
  LorinMessage closeFileIntrMsg(int targetDevice, int handle) =>
      LorinMessage.from(LorinPublicRequestBody.closeFile(targetDevice, handle));

  @override
  LorinMessage deleteFileIntrMsg(int targetDevice, String path) {
    return LorinMessage.from(
        LorinPublicRequestBody.deleteFile(targetDevice, path));
  }

  @override
  LorinMessage openFileIntrMsg(
      int targetDevice, int openFileType, String path) {
    return LorinMessage.from(
        LorinPublicRequestBody.openFile(targetDevice, openFileType, path));
  }

  @override
  LorinMessage readFileInfoIntrMsg(int targetDevice, String path) {
    return LorinMessage.from(
        LorinPublicRequestBody.readFileInfo(targetDevice, path));
  }

  @override
  LorinMessage readWriteFileIntrMsg(int targetDevice, int handle, int offset,
      {int? length, Uint8List? data}) {
    return LorinMessage.from(LorinPublicRequestBody.readWriteFile(
      targetDevice,
      handle,
      offset,
      length: length,
      data: data,
    ));
  }

  @override
  LorinMessage renameFileIntrMsg(
      int targetDevice, String oldPath, String newPath) {
    return LorinMessage.from(
        LorinPublicRequestBody.renameFile(targetDevice, oldPath, newPath));
  }

  @override
  LorinMessage verifyFileIntrMsg(
    int targetDevice,
    int handle,
    int offset, {
    int? fileSize,
    int? crc32,
  }) {
    return LorinMessage.from(LorinPublicRequestBody.verifyFile(
      targetDevice,
      handle,
      offset,
      fileSize: fileSize,
      crc32: crc32,
    ));
  }

  @override
  LorinMessage getFileListIntrMsg(int targetDevice, int index, int method,
      int depth, String path, String name) {
    return LorinMessage.from(LorinPublicRequestBody.getFileList(
        targetDevice, index, method, depth, path, name));
  }

  @override
  LorinMessage queryFirmwareUpdateStatusIntrMsg(
    int targetDevice,
  ) {
    return LorinMessage.from(
        LorinPublicRequestBody.queryFirmwareUpdateStatus(targetDevice));
  }

  @override
  LorinMessage queryForceFirmwareUpdateStatusIntrMsg({int? targetDevice}) {
    return LorinMessage.from(
        LorinPublicRequestBody.queryForceFirmwareUpdateStatus(
            targetDevice: targetDevice));
  }

  @override
  LorinMessage clearFirmwareUpdateStatusIntrMsg(
    int forceUpgradeStatus,
    int lowVersion,
    int highVersion, {
    int? targetDevice,
  }) {
    return LorinMessage.from(LorinPublicRequestBody.clearFirmwareUpdateStatus(
        forceUpgradeStatus, lowVersion, highVersion,
        targetDevice: targetDevice));
  }

  @override
  LorinMessage startFirmwareUpdateIntrMsg(int targetDevice,
      {bool isStart = true}) {
    return LorinMessage.from(LorinPublicRequestBody.startFirmwareUpdate(
        targetDevice,
        isStart: isStart));
  }

  @override
  LorinMessage startForceFirmwareUpdateIntrMsg(int targetDevice,
      int forceUpgradeStatus, int lowVersion, int highVersion) {
    return LorinMessage.from(LorinPublicRequestBody.startForceFirmwareUpdate(
        targetDevice, forceUpgradeStatus, lowVersion, highVersion));
  }
}
